package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.xmy.cultivate.entity.AuthAdminContent;
import com.xmy.cultivate.entity.TeacherContinueInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.cultivate.entity.response.ContinueInfo;
import com.xmy.cultivate.entity.views.LeadDataRs;
import com.xmy.cultivate.entity.views.RenewClassRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 教师续报信息 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2023-06-18
 */
public interface TeacherContinueInfoMapper extends BaseMapper<TeacherContinueInfo> {

    /**
     * 获取续班率老师，按校区
     * @param wrapper
     * @return
     */
    @Select("select * from renew_record_view ${ew.customSqlSegment}")
    public abstract List<ContinueInfo> getRenewRecordOld(@Param(Constants.WRAPPER) Wrapper wrapper);


    /**
     * 获取续班率老师，按个人
     * @param wrapper
     * @return
     */
    @Select("select * from renew_record_person_view ${ew.customSqlSegment}")
    public abstract List<ContinueInfo> getRenewRecordPerson(@Param(Constants.WRAPPER) Wrapper wrapper);

    /**
     * 获取续班率老师，按校区
     * @param wrapper
     * @return
     */
    @Select("select * from recordclass_school_view ${ew.customSqlSegment}")
    public abstract List<ContinueInfo> getRenewRecordSchool(@Param(Constants.WRAPPER) Wrapper wrapper);


    @Select({"<script>",
            "SELECT",
            "t.*,",
            "count(t.id) as student_all_count,",
            "getSchoolName(t.school_id) as school_name,",
            "SUM( CASE WHEN is_presort in(1,2,3) THEN 1 ELSE 0 END ) AS scheduling_count,",
            "SUM( CASE WHEN is_presort in(1,2,3) and presort_date BETWEEN #{startDate} AND #{endDate}  THEN 1 ELSE 0 END ) AS date_scheduling_count",
            "<if test= 'type == 6'>",
                ",t01.pid as schoolPid",
                "FROM ",
                "( SELECT * FROM school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t01 ",
                "LEFT JOIN (",
            "</if>",
            "<if test= 'type != 6'>",
                "FROM ( ",
            "</if>",
                "SELECT",
                "t01.id,",
                "t01.school_id,",
                "t03.year_class_id,",
                "t03.course_type_id,",
                "t01.student_id,",
                "t01.grade_id,",
                "t01.teacher_id,",
                "t03.`name` AS grade_name,",
                "t01.subjects_id,",
                "t01.lesson_type,",
                "t02.is_presort,",
                "DATE_FORMAT(t02.created_at, '%Y-%m-%d') as presort_date,",
                "getStaffNameForId(t01.teacher_id) AS teacher_name ",
                "FROM",
                "(",
                    "SELECT",
                    "t1.id,",
                    "t1.subjects_id,",
                    "t1.student_id,",
                    "t1.grade_id,",
                    "t1.lesson_type,",
                    "( CASE WHEN t8.in_school_id IS NOT NULL THEN t8.in_school_id ELSE t1.school_id END ) AS school_id,",

                    "<choose>",
                        "<when test= 'isHistory == 1'>",
                            "t2.teacher_id AS tack_teacher_id, ",
                            "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t2.teacher_id END ) AS teacher_id ",
                        "</when>",
                        "<otherwise>",
                            "t1.teacher_id AS tack_teacher_id,",
                            "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t1.teacher_id END ) AS teacher_id ",
                        "</otherwise>",
                    "</choose>",

                    "FROM",
                    "<choose>",
                        "<when test= 'isHistory == 1'>",
                            "student_grade_history AS t1 ",
                            "INNER JOIN grade as t2 on t1.grade_id = t2.id",
                        "</when>",
                        "<otherwise>",
                             "student_grade_view AS t1 ",
                        "</otherwise>",
                    "</choose>",
                    "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
                    "AND t7.deleted = 0 ",
                    "AND t7.type = 1 ",
                    "AND t1.student_id = t7.student_id ",
                    "AND t1.year_part = t7.year_part ",
                    "AND t1.quarter_num = t7.quarter_num ",
                    "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
                    "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
                    "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
                    "AND t1.quarter_num = t8.quarter_num ",
                    "AND t1.subjects_id = t8.subjects_id ",
                    "AND t1.student_id = t8.student_id ",
                    "WHERE",
                    "t1.year_part = ${yearPart} ",
                    "AND t1.quarter_num = ${quarterNum} ",
                    "<when test= 'isHistory == 1'>",
                        "AND '${endDate}' BETWEEN t1.start_date AND t1.end_date",
                    "</when>",
                    "AND t1.lesson_type = ${lessonType} ",
                    "AND t7.id IS NULL ",
                    "AND t1.deleted = 0 ",
                    "AND t1.STATUS IN ( 1, 5, 6 )  ",
                    "AND t1.is_last = 1 ",
                    "and t1.is_makeup = 0",
                    "and (t1.reading_status in(1,4,5,6) or (t1.reading_status=3 and t1.use_course_count &gt; 0))",
                    "and t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
                    "<if test= 'type != 7'>",
                        "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                            "<when test='quarterNum==2'>",
                                "and t1.year_class_id &lt; 10",
                            "</when>",
                            "<when test='quarterNum!=2'>",
                                "and t1.year_class_id &lt; 10",
                            "</when>",
                        "</when>",
                    "</if>",
                    "GROUP BY",
                    "t1.school_id,",
                    "t1.student_id,",
                    "<choose>",
                        "<when test= 'isHistory == 1'>",
                            "t2.teacher_id,",
                        "</when>",
                        "<otherwise>",
                            "t1.teacher_id,",
                        "</otherwise>",
                    "</choose>",
                    "t1.subjects_id ",
                ") AS t01",
                "LEFT JOIN (",
                    "SELECT",
                    "* ",
                    "FROM",
                    "student_grade_continue ",
                    "WHERE",
                    "year_part = ${nextYearPart} ",
                    "AND quarter_num = ${nextQuarterNum} ",
                    "AND lesson_type = ${lessonType} ",
                    "AND deleted = 0 ",
                    "AND is_presort in(1,2,3) ",
                    "AND '${endDate}' BETWEEN start_date AND end_date",
                    "GROUP BY",
                    "student_id,",
                    "subjects_id ",
                    ") AS t02 ON t01.student_id = t02.student_id ",
                    "AND t01.subjects_id = t02.subjects_id",
                    "LEFT JOIN grade AS t03 ON t01.grade_id = t03.id ",
                ") AS t",
                "<if test= 'type == 6'>",
                    "ON t.school_id = t01.school_id ",
                "</if>",
                "where 1=1",
                "<when test='trackId!=null and trackId!=&apos;&apos; and type != 4'>",
                    "and t.teacher_id in(select sourse_id from track_detail where deleted = 0 and track_id = ${trackId})",
                "</when>",
                "<if test= 'type == 3'>",
                    "and teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
                "</if>",
                "<when test='trackId!=null and trackId!=&apos;&apos; and type == 4'>",
                    "AND t.school_id in(select sourse_id from track_detail where deleted = 0 and track_id = ${trackId})",
                "</when>",

                // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
                "AND ((",
                "year_class_id in(${authAdminContent.yearClassIds})",
                "AND subjects_id in(${authAdminContent.subjectsIds})",
                "<when test='yearClassId!=null'>",
                    "AND year_class_id IN (${yearClassId})",
                "</when>",
                "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                    "AND subjects_id in (${subjectsId})",
                "</when>",
                "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                    "AND t.school_id in(${schoolId})",
                "</when>",
                ") OR (",
                "t.teacher_id = ${leadDataRs.teacherId} AND t.school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
                // ---权限数据结束---

                "<when test='classTypeId!=null'>",
                    "and course_type_id IN (${classTypeId})",
                "</when>",
                "<when test='name!=null and name!=&apos;&apos; '>",
                    "and teacher_name LIKE '%${name}%'",
                "</when>",
                "<if test= 'type == 6'>",
                    "and t.school_id is not null",
                "</if>",
                "GROUP BY",
                "<if test= 'type == 1 or type == 3'>",
                    "t.teacher_id",
                "</if>",
                "<if test= 'type == 2'>",
                    "t.school_id,t.teacher_id",
                "</if>",
                "<if test= 'type == 4 or type == 6'>",
                    "t.school_id",
                "</if>",
                "<if test= 'type == 7'>",
                    "year_class_id",
                "</if>",
                "<if test= 'type == 7'>",
                    "ORDER BY year_class_id DESC",
                "</if>",
            "</script>"})
    public abstract List<ContinueInfo> getRenewRecord(@Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("trackId") String trackId, @Param("yearClassId") String yearClassId, @Param("classTypeId") String classTypeId, @Param("name") String name, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs, @Param("isHistory") Integer isHistory);

    @Select({"<script>",
            "WITH with_tb01 AS (",
            "SELECT",
            "school_id,",
            "IF ( pid = 0, school_id, pid ) AS pid ",
            "FROM",
            "school_quarter ",
            "WHERE",
            "year_part = ${yearPart}",
            "AND quarter_num = ${quarterNum} ",
//            "GROUP BY IF( pid = 0, school_id, pid ) ",
            "),",
            "with_tb02 AS (",
            "SELECT",
            "t1.school_id AS school_id,",
            "t4.id AS teacher_id,",
            "t4.`name` AS teacher_name,",
            "t2.`name` AS duty_name,",
            "t3.`name` AS department_name",
            "<if test= '( paymentStaffType == 2 or paymentStaffType == 4 ) and ( paymentStaff == 3 || paymentStaff == 2 ||  paymentStaff == 6 )'>",
            ",t5.year_class_id,",
            "t5.subjects_id ",
            "</if>",
            "FROM",
            "organization_department_principal AS t1",
            "INNER JOIN org_duty AS t2 ON t1.duty_id = t2.id",
            "INNER JOIN department AS t3 ON t1.department_id = t3.id",
            "INNER JOIN staff AS t4 ON t1.staff_id = t4.id ",
            "<if test= '( paymentStaffType == 2 or paymentStaffType == 4 ) and ( paymentStaff == 3 || paymentStaff == 2 ||  paymentStaff == 6 )'>",
            // 管理数据-年级负责人
            "INNER JOIN org_principal_content  as t5 on t1.id = t5.principal_id",
            "INNER JOIN with_tb01 on t1.school_id = with_tb01.school_id",
            "<if test= ' paymentStaff == 6 '>",
            "INNER JOIN org_principal_items AS t6 ON t1.id = t6.principal_id AND t6.projects_id = 12",
            "</if>",
            "</if>",
            "WHERE",
            "t3.id IN ( ${departmentId} ) ",
            "AND t2.duty_type = ${dutyType} ",
            "AND t1.year_part = ${yearPart}",
            "AND t1.quarter_num = ${quarterNum} ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t1.staff_id = ${teacherId} ",
            "</when>",
            "<choose>",
                "<when test= 'paymentStaffType == 1'>",
                    "AND t1.`level` in (1,2) ",
                "</when>",
                "<otherwise>",
                    "AND t1.`level` = 1 ",
                "</otherwise>",
            "</choose>",
            "<if test= 'paymentStaffType == 1 or paymentStaffType == 3'>",
            "GROUP BY t1.staff_id ",
            "</if>",
            "<if test= 'paymentStaffType == 4'>",
            "GROUP BY t1.school_id ",
            "</if>",
            ")",

            "SELECT",
            "t.school_id,",
            "t.year_class_id,",
            "t.course_type_id,",
            "t.presort_date,",
            "<if test= 'paymentStaffType == 1 or paymentStaffType == 3 or ( paymentStaffType == 2 and isDetails == 1 ) or ( paymentStaffType == 4 and isDetails == 1 )'>",
                // 个人数据
                "t.teacher_id,",
                "getStaffNameForId ( t.teacher_id ) AS teacher_name,",
            "</if>",
            "<if test= 'paymentStaffType == 2 and isDetails != 1 '>",
                // 管理数据
                "with_tb02.teacher_id,",
                "with_tb02.teacher_name,",
            "</if>",
            "count(t.id) as student_all_count,",
            "getSchoolName(t.school_id) as school_name,",
            "SUM( CASE WHEN is_presort in(1,2,3) THEN 1 ELSE 0 END ) AS scheduling_count,",
            "SUM( CASE WHEN is_presort in(1,2,3) and presort_date BETWEEN #{startDate} AND #{endDate}  THEN 1 ELSE 0 END ) AS date_scheduling_count,",
            "t01.school_pid",
            "FROM ",
            "( SELECT school_id,IF( pid = 0, school_id, pid ) AS school_pid FROM school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t01 ",
            "LEFT JOIN (",
            "SELECT",
            "t01.id,",
            "t01.school_id,",
            "t03.year_class_id,",
            "t03.course_type_id,",
            "t01.student_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t03.`name` AS grade_name,",
            "t01.subjects_id,",
            "t01.lesson_type,",
            "t02.is_presort,",
            "DATE_FORMAT(t02.created_at, '%Y-%m-%d') as presort_date,",
            "getStaffNameForId(t01.teacher_id) AS teacher_name ",
            "FROM",
            "(",
            "SELECT",
            "t1.id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.grade_id,",
            "t1.lesson_type,",

            "<choose>",
                "<when test= 'isHistory == 1'>",
                    "t2.teacher_id AS tack_teacher_id,",
                    "<choose>",
                        "<if test= 'paymentStaff == 1 and paymentStaffType == 1 '>",
                            "(CASE WHEN t8.in_school_id is not null  THEN 0 ELSE t1.school_id END ) as school_id,",
                            "(CASE WHEN t8.schoolmaster_id is not null  THEN 0 ELSE t2.teacher_id END ) AS teacher_id",
                        "</if>",
                        "<if test= 'paymentStaff == 1 and paymentStaffType == 3'>",
                            "(CASE WHEN t8.in_school_id is not null  THEN t8.in_school_id ELSE 0 END ) as school_id,",
                            "(CASE WHEN t8.schoolmaster_id is not null  THEN t8.schoolmaster_id ELSE 0 END ) AS teacher_id",
                        "</if>",
                        "<otherwise>",
                            "(CASE WHEN t8.in_school_id is not null  THEN t8.in_school_id ELSE t1.school_id END ) as school_id,",
                            "(CASE WHEN t8.schoolmaster_id is not null  THEN t8.schoolmaster_id ELSE t2.teacher_id END ) AS teacher_id",
                        "</otherwise>",
                    "</choose>",
                "</when>",
                "<otherwise>",
                    "t1.teacher_id AS tack_teacher_id,",
                    "<choose>",
                        "<if test= 'paymentStaff == 1 and paymentStaffType == 1 '>",
                            "(CASE WHEN t8.in_school_id is not null  THEN 0 ELSE t1.school_id END ) as school_id,",
                            "(CASE WHEN t8.schoolmaster_id is not null  THEN 0 ELSE t1.teacher_id END ) AS teacher_id",
                        "</if>",
                        "<if test= 'paymentStaff == 1 and paymentStaffType == 3'>",
                            "(CASE WHEN t8.in_school_id is not null  THEN t8.in_school_id ELSE 0 END ) as school_id,",
                            "(CASE WHEN t8.schoolmaster_id is not null  THEN t8.schoolmaster_id ELSE 0 END ) AS teacher_id",
                        "</if>",
                        "<otherwise>",
                            "(CASE WHEN t8.in_school_id is not null  THEN t8.in_school_id ELSE t1.school_id END ) as school_id,",
                            "(CASE WHEN t8.schoolmaster_id is not null  THEN t8.schoolmaster_id ELSE t1.teacher_id END ) AS teacher_id",
                        "</otherwise>",
                    "</choose>",
                "</otherwise>",
            "</choose>",

            "FROM",
            "<choose>",
                "<when test= 'isHistory == 1'>",
                    "student_grade_history AS t1 ",
                    "INNER JOIN grade as t2 on t1.grade_id = t2.id",
                "</when>",
                "<otherwise>",
                    "student_grade_view AS t1 ",
                "</otherwise>",
            "</choose>",
            "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
            "AND t7.deleted = 0 ",
            "AND t7.type = 1 ",
            "AND t1.student_id = t7.student_id ",
            "AND t1.year_part = t7.year_part ",
            "AND t1.quarter_num = t7.quarter_num ",
            "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
            "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
            "AND t1.quarter_num = t8.quarter_num ",
            "AND t1.subjects_id = t8.subjects_id ",
            "AND t1.student_id = t8.student_id ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "<when test= 'isHistory == 1'>",
                "AND '${endDate}' BETWEEN t1.start_date AND t1.end_date",
            "</when>",
            "AND t1.lesson_type = ${lessonType} ",
            "AND t7.id IS NULL ",
            "AND t1.deleted = 0 ",
            "AND t1.STATUS IN ( 1, 5, 6 )  ",
            "AND t1.is_last = 1 ",
            "and t1.is_makeup = 0",
            "and (t1.reading_status in(1,4,5,6) or (t1.reading_status=3 and t1.use_course_count &gt; 0))",
            "and t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
            "<if test= 'type != 7'>",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
            "<when test='quarterNum==2'>",
            "and t1.year_class_id &lt; 10",
            "</when>",
            "<when test='quarterNum!=2'>",
            "and t1.year_class_id &lt; 10",
            "</when>",
            "</when>",
            "</if>",
            "GROUP BY",
            "t1.school_id,",
            "t1.student_id,",
            "<choose>",
                "<when test= 'isHistory == 1'>",
                    "t2.teacher_id,",
                "</when>",
                "<otherwise>",
                    "t1.teacher_id,",
                "</otherwise>",
            "</choose>",
            "t1.subjects_id ",
            ") AS t01",
            "LEFT JOIN (",
            "SELECT",
            "* ",
            "FROM",
            "student_grade_continue ",
            "WHERE",
            "year_part = ${nextYearPart} ",
            "AND quarter_num = ${nextQuarterNum} ",
            "AND lesson_type = ${lessonType} ",
            "AND deleted = 0 ",
            "AND is_presort in(1,2,3) ",
            "AND '${endDate}' BETWEEN start_date AND end_date",
            "GROUP BY",
            "student_id,",
            "subjects_id ",
            ") AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id",
            "LEFT JOIN grade AS t03 ON t01.grade_id = t03.id ",
            ") AS t ON t.school_id = t01.school_id ",

            "<if test= 'paymentStaffType == 1 or paymentStaffType == 3'>",
                "<choose>",
                    "<when test= 'paymentStaff == 4'>",
                        // 个人数据-火种
                        "INNER JOIN auth_teacher_classify AS with_tb02 ON t.teacher_id = with_tb02.teacher_id AND with_tb02.type = 3 ",
                    "</when>",
                "<when test= 'paymentStaff == 5'>",
                    // 个人数据-专职
                    "INNER JOIN auth_teacher_classify AS with_tb02 ON t.teacher_id = with_tb02.teacher_id AND with_tb02.type = 2 ",
                "</when>",
                "<otherwise>",
                    // 个人数据-教学主管、年级负责人
                    "INNER JOIN with_tb02 ON t.teacher_id = with_tb02.teacher_id",
                "</otherwise>",
                "</choose>",
            "</if>",
            "<if test= 'paymentStaffType == 2'>",
                "INNER JOIN with_tb02 on t.school_id = with_tb02.school_id",
                "<if test= 'paymentStaff == 2 || paymentStaff == 3 || paymentStaff == 6'>",
                    // 年级负责人
                    "AND t.year_class_id = with_tb02.year_class_id",
                    "AND t.subjects_id = with_tb02.subjects_id",
                "</if>",
            "</if>",
            "<if test= 'paymentStaffType == 4'>",
                // 小校区-校区赛道
                "INNER JOIN with_tb02 on t.school_id = with_tb02.school_id",
            "</if>",

            "where t.school_id is not null",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "t.year_class_id in(${authAdminContent.yearClassIds})",
            "AND t.subjects_id in(${authAdminContent.subjectsIds})",
            "<when test='yearClassId!=null'>",
                "AND t.year_class_id IN (${yearClassId})",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "AND t.subjects_id in (${subjectsId})",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                "AND t.school_id in(${schoolId})",
            "</when>",
            ") OR (",
            "t.teacher_id = ${leadDataRs.teacherId} AND t.school_id IN ( ${leadDataRs.schoolIds} ) AND t.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
            // ---权限数据结束---

            "<when test='classTypeId!=null'>",
                "and t.course_type_id IN (${classTypeId})",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
                "and teacher_name LIKE '%${name}%'",
            "</when>",

            "<if test= 'paymentStaffType == 1 or paymentStaffType == 3 or ( paymentStaffType == 2 and isDetails == 1 ) or ( paymentStaffType == 4 and isDetails == 1 )'>",
                // 个人数据
                "GROUP BY t.teacher_id,t.school_id",
                "<if test= '(paymentStaff == 3 || paymentStaff == 2 || paymentStaff == 6 )and paymentStaffType == 2 and isDetails == 1 '>",
                    // 年级负责人
                    ",t.year_class_id",
                "</if>",
            "</if>",
            "<if test= 'paymentStaffType == 2 and isDetails != 1'>",
                // 管理数据
                "GROUP BY with_tb02.teacher_id,t.school_id ",
                "<if test= 'paymentStaff == 2 || paymentStaff == 3 || paymentStaff == 6'>",
                    // 年级负责人
                    ",t.year_class_id,t.subjects_id",
                "</if>",
            "</if>",
            "<if test= 'paymentStaffType == 4 and isDetails != 1'>",
                // 校区赛道
                "GROUP BY t.school_id",
            "</if>",
            "</script>"})
    public abstract List<ContinueInfo> getRenewRecordV2(@Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("trackId") String trackId, @Param("yearClassId") String yearClassId, @Param("classTypeId") String classTypeId, @Param("name") String name, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs, @Param("paymentStaff") Integer paymentStaff, @Param("paymentStaffType") Integer paymentStaffType, @Param("departmentId") String departmentId, @Param("dutyType") Integer dutyType, @Param("isDetails") Integer isDetails, @Param("teacherId") String teacherId, @Param("isHistory") Integer isHistory);


    @Select({"<script>",
            "SELECT",
            "*,",
            "getStaffNameForId ( tack_teacher_id ) AS teacher_name,",
            "getSchoolName ( school_id ) AS school_name",
            "FROM",
            "(",
                "SELECT",
                "t01.id,",
                "t01.school_id,",
                "t01.year_class_id,",
                "t01.course_type_id,",
                "t01.student_id,",
                "t01.grade_id,",
                "t01.teacher_id,",
                "t01.grade_name,",
                "t01.subjects_id,",
                "t01.lesson_type,",
                "t02.is_presort,",
                "t04.`name` as student_name,",
                "tack_teacher_id, ",
                "DATE_FORMAT( t02.created_at, '%Y-%m-%d' ) AS presort_date, ",
                "sum( residue_course_count_all ) AS residue_course_count ",
                "FROM",
                "(",
                    "SELECT",
                    "t1.id, ",
                    "t1.student_id,",
                    "t1.grade_id,",
                    "t1.subjects_id,",
                    "t1.lesson_type,",
                    "t2.`name` AS grade_name,",
                    "t2.year_class_id,",
                    "t2.course_type_id,",
                    "t2.teacher_id AS tack_teacher_id,",
                    "( CASE WHEN t8.in_school_id IS NOT NULL THEN t8.in_school_id ELSE t2.school_id END ) AS school_id,",
                    "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t2.teacher_id END ) AS teacher_id, ",
                    "sum(IFNULL( t9.residue_course_count, 0 )) AS residue_course_count_all ",
                    "FROM",
                    "<choose>",
                        "<when test= 'isHistory == 1'>",
                            "student_grade_history AS t1 ",
                        "</when>",
                        "<otherwise>",
                            "student_grade AS t1 ",
                        "</otherwise>",
                    "</choose>",
                    "LEFT JOIN grade AS t2 ON t1.grade_id = t2.id ",
                    "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
                    "AND t7.deleted = 0 ",
                    "AND t7.type = 1 ",
                    "AND t1.student_id = t7.student_id ",
                    "AND t1.year_part = t7.year_part ",
                    "AND t1.quarter_num = t7.quarter_num ",
                    "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
                    "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
                    "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
                    "AND t1.quarter_num = t8.quarter_num ",
                    "AND t1.subjects_id = t8.subjects_id ",
                    "AND t1.student_id = t8.student_id ",
                    "LEFT JOIN order_detail AS t9 ON t9.student_id = t1.student_id ",
                    "AND t9.school_id = t1.school_id",
                    "AND t9.subjects_id = t1.subjects_id",
                    "AND t9.year_part = t1.year_part",
                    "AND t9.lesson_type = t1.lesson_type",
                    "AND t9.quarter_num = t1.quarter_num",
                    "AND t9.STATUS &lt;&gt; 2",
                    "AND t9.deleted = 0",
                    "WHERE",
                    "t1.year_part = ${yearPart} ",
                    "AND t1.quarter_num = ${quarterNum} ",
                    "<when test= 'isHistory == 1'>",
                        "AND '${endDate}' BETWEEN t1.start_date AND t1.end_date",
                    "</when>",
                    "AND t1.lesson_type = 1 ",
                    "AND t7.id IS NULL ",
                    "AND t1.deleted = 0 ",
                    "AND t1.STATUS IN ( 1, 5, 6 )  ",
                    "AND t1.is_last = 1 ",
                    "and t1.is_makeup = 0",
                    "and (t1.reading_status in(1,4,5,6) or (t1.reading_status=3 and t1.use_course_count&gt;0))",
                    "and t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
                    "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                        "<when test='quarterNum==2'>",
                            "and t1.year_class_id &lt; 13",
                        "</when>",
                        "<when test='quarterNum!=2'>",
                            "and t1.year_class_id &lt; 13",
                        "</when>",
                    "</when>",
                    "GROUP BY",
                    "t1.school_id,",
                    "t1.student_id,",
                    "t1.subjects_id ",
                ") AS t01",
                "LEFT JOIN (",
                    "SELECT",
                    "* ",
                    "FROM",
                    "student_grade_continue ",
                    "WHERE",
                    "year_part = ${nextYearPart} ",
                    "AND quarter_num = ${nextQuarterNum}",
                    "AND lesson_type = 1 ",
                    "AND deleted = 0 ",
                    "AND is_presort in(1,2,3) ",
                    "AND '${endDate}' BETWEEN start_date AND end_date",
                    "GROUP BY",
                    "student_id,",
                    "subjects_id ",
                ") AS t02 ON t01.student_id = t02.student_id",
                "AND t01.subjects_id = t02.subjects_id",
                "LEFT JOIN student AS t04 ON t01.student_id = t04.id",
                "GROUP BY ",
                "school_id,student_id,subjects_id,teacher_id ",
            ") AS t ",
            "WHERE",
            "1 = 1 ",
            "and is_presort in(1,2,3)",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
                "and grade_id IN (${gradeId}) ",
            "</when>",
            "<when test='detailType == 3 and startDate!=&apos;&apos; and endDate!=&apos;&apos;'>",
                "and presort_date BETWEEN #{startDate} AND #{endDate}",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
                "and course_type_id IN (${classTypeId})",
            "</when>",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "year_class_id in(${authAdminContent.yearClassIds})",
                "and subjects_id in(${authAdminContent.subjectsIds})",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
                "and year_class_id IN (${yearClassId})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                "AND teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                "AND school_id IN (${schoolId}) ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                "and subjects_id in (${subjectsId}) ",
            "</when>",
            ") OR (",
            "teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
            // ---权限数据结束---
            "ORDER BY residue_course_count DESC ",
            "</script>"})
    public abstract IPage<ContinueInfo> getRenewRecordDetail(IPage<?> iPage, @Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("teacherId") String teacherId, @Param("gradeId") String gradeId, @Param("yearClassId") String yearClassId, @Param("classTypeId") String classTypeId, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs, @Param("isHistory") Integer isHistory, @Param("detailType") Integer detailType);

    @Select({"<script>",
            "WITH with_tb01 AS (",
            "SELECT",
            "school_id,",
            "IF ( pid = 0, school_id, pid ) AS pid ",
            "FROM",
            "school_quarter ",
            "WHERE",
            "year_part = ${yearPart}",
            "AND quarter_num = ${quarterNum} ",
//            "GROUP BY IF( pid = 0, school_id, pid ) ",
            "),",
            "with_tb02 AS (",
            "SELECT",
            "t1.school_id AS school_id,",
            "t4.id AS teacher_id,",
            "t4.`name` AS teacher_name,",
            "t2.`name` AS duty_name,",
            "t3.`name` AS department_name",
            "<if test= 'paymentStaffType == 2 and ( paymentStaff == 3 || paymentStaff == 2 ||  paymentStaff == 6 )'>",
            ",t5.year_class_id,",
            "t5.subjects_id ",
            "</if>",
            "FROM",
            "organization_department_principal AS t1",
            "INNER JOIN org_duty AS t2 ON t1.duty_id = t2.id",
            "INNER JOIN department AS t3 ON t1.department_id = t3.id",
            "INNER JOIN staff AS t4 ON t1.staff_id = t4.id ",
            "<if test= 'paymentStaffType == 2 and ( paymentStaff == 3 || paymentStaff == 2 ||  paymentStaff == 6 )'>",
                // 管理数据-年级负责人
                "INNER JOIN org_principal_content  as t5 on t1.id = t5.principal_id",
                "INNER JOIN with_tb01 on t1.school_id = with_tb01.school_id",
                "<if test= ' paymentStaff == 6 '>",
                    "INNER JOIN org_principal_items AS t6 ON t1.id = t6.principal_id AND t6.projects_id = 13",
                "</if>",
            "</if>",
            "WHERE",
            "t3.id IN ( ${departmentId} ) ",
            "AND t2.duty_type = ${dutyType} ",
            "AND t1.year_part = ${yearPart}",
            "AND t1.quarter_num = ${quarterNum} ",
            "<when test='paymentStaffId!=null and paymentStaffId!=&apos;&apos; '>",
            "AND t1.staff_id = ${paymentStaffId} ",
            "</when>",
            ")",

            "SELECT",
            "t.*,",
            "getStaffNameForId ( tack_teacher_id ) AS teacher_name,",
            "getSchoolName ( t.school_id ) AS school_name",
            "FROM",
            "(",
            "SELECT",
            "school_id,",
            "IF ( pid = 0, school_id, pid ) AS school_pid ",
            "FROM",
            "school_quarter ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND deleted = 0 ",
            ") AS t1",
            "LEFT JOIN (",
                "SELECT",
                "t01.id,",
                "t01.school_id,",
                "t01.year_class_id,",
                "t01.course_type_id,",
                "t01.student_id,",
                "t01.grade_id,",
                "t01.teacher_id,",
                "t01.grade_name,",
                "t01.subjects_id,",
                "t01.lesson_type,",
                "t02.is_presort,",
                "t04.`name` as student_name,",
                "tack_teacher_id, ",
                "DATE_FORMAT( t02.created_at, '%Y-%m-%d' ) AS presort_date, ",
                "sum( residue_course_count_all ) AS residue_course_count ",
                "FROM",
                "(",
                "SELECT",
                "t1.id, ",
                "t1.student_id,",
                "t1.grade_id,",
                "t1.subjects_id,",
                "t1.lesson_type,",
                "t2.`name` AS grade_name,",
                "t2.year_class_id,",
                "t2.course_type_id,",
                "t2.teacher_id AS tack_teacher_id,",
                "<choose>",
                    "<if test= 'paymentStaff == 1 and paymentStaffType == 1 '>",
                        "(CASE WHEN t8.in_school_id is not null  THEN 0 ELSE t1.school_id END ) as school_id,",
                        "(CASE WHEN t8.schoolmaster_id is not null  THEN 0 ELSE t2.teacher_id END ) AS teacher_id,",
                    "</if>",
                    "<if test= 'paymentStaff == 1 and paymentStaffType == 3'>",
                        "(CASE WHEN t8.in_school_id is not null  THEN t8.in_school_id ELSE 0 END ) as school_id,",
                        "(CASE WHEN t8.schoolmaster_id is not null  THEN t8.schoolmaster_id ELSE 0 END ) AS teacher_id,",
                    "</if>",
                    "<otherwise>",
                        "(CASE WHEN t8.in_school_id is not null  THEN t8.in_school_id ELSE t1.school_id END ) as school_id,",
                        "(CASE WHEN t8.schoolmaster_id is not null  THEN t8.schoolmaster_id ELSE t2.teacher_id END ) AS teacher_id,",
                    "</otherwise>",
                "</choose>",
                "sum(IFNULL( t9.residue_course_count, 0 )) AS residue_course_count_all ",
                "FROM",
                "<choose>",
                    "<when test= 'isHistory == 1'>",
                        "student_grade_history AS t1 ",
                    "</when>",
                    "<otherwise>",
                        "student_grade AS t1 ",
                    "</otherwise>",
                "</choose>",
                "LEFT JOIN grade AS t2 ON t1.grade_id = t2.id ",
                "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
                "AND t7.deleted = 0 ",
                "AND t7.type = 1 ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.year_part = t7.year_part ",
                "AND t1.quarter_num = t7.quarter_num ",
                "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
                "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
                "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
                "AND t1.quarter_num = t8.quarter_num ",
                "AND t1.subjects_id = t8.subjects_id ",
                "AND t1.student_id = t8.student_id ",
                "LEFT JOIN order_detail AS t9 ON t9.student_id = t1.student_id ",
                "AND t9.school_id = t1.school_id",
                "AND t9.subjects_id = t1.subjects_id",
                "AND t9.year_part = t1.year_part",
                "AND t9.lesson_type = t1.lesson_type",
                "AND t9.quarter_num = t1.quarter_num",
                "AND t9.STATUS &lt;&gt; 2",
                "AND t9.deleted = 0",
                "WHERE",
                "t1.year_part = ${yearPart} ",
                "AND t1.quarter_num = ${quarterNum} ",
                "<when test= 'isHistory == 1'>",
                    "AND '${endDate}' BETWEEN t1.start_date AND t1.end_date",
                "</when>",
                "AND t1.lesson_type = 1 ",
                "AND t7.id IS NULL ",
                "AND t1.deleted = 0 ",
                "AND t1.STATUS IN ( 1, 5, 6 )  ",
                "AND t1.is_last = 1 ",
                "and t1.is_makeup = 0",
                "and (t1.reading_status in(1,4,5,6) or (t1.reading_status=3 and t1.use_course_count&gt;0))",
                "and t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
                "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                    "<when test='quarterNum==2'>",
                        "and t1.year_class_id &lt; 13",
                    "</when>",
                    "<when test='quarterNum!=2'>",
                        "and t1.year_class_id &lt; 13",
                    "</when>",
                "</when>",
                "GROUP BY",
                "t1.school_id,",
                "t1.student_id,",
                "t1.subjects_id ",
                ") AS t01",
                "LEFT JOIN (",
                "SELECT",
                "* ",
                "FROM",
                "student_grade_continue ",
                "WHERE",
                "year_part = ${nextYearPart} ",
                "AND quarter_num = ${nextQuarterNum}",
                "AND lesson_type = 1 ",
                "AND deleted = 0 ",
                "AND is_presort in(1,2,3) ",
                "AND '${endDate}' BETWEEN start_date AND end_date",
                "GROUP BY",
                "student_id,",
                "subjects_id ",
                ") AS t02 ON t01.student_id = t02.student_id",
                "AND t01.subjects_id = t02.subjects_id",
                "LEFT JOIN student AS t04 ON t01.student_id = t04.id",
                "GROUP BY ",
                "school_id,student_id,subjects_id,teacher_id ",
            ") AS t ON t.school_id = t1.school_id ",
            "<if test= 'paymentStaffType == 2'>",
                "INNER JOIN with_tb02 on t.school_id = with_tb02.school_id",
                "<if test= 'paymentStaff == 2 || paymentStaff == 3 || paymentStaff == 6'>",
                    // 年级负责人
                    "AND t.year_class_id = with_tb02.year_class_id",
                    "AND t.subjects_id = with_tb02.subjects_id",
                "</if>",
            "</if>",

            "WHERE",
            "1 = 1 ",
            "and t.is_presort in(1,2,3)",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
                "and t.grade_id IN (${gradeId}) ",
            "</when>",
            "<when test='detailType == 3 and startDate!=&apos;&apos; and endDate!=&apos;&apos;'>",
                "and presort_date BETWEEN #{startDate} AND #{endDate}",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
                "and t.course_type_id IN (${classTypeId})",
            "</when>",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
                "AND ((",
                "t.year_class_id in(${authAdminContent.yearClassIds})",
                "and t.subjects_id in(${authAdminContent.subjectsIds})",
                "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
                    "AND t.year_class_id IN (${yearClassId})",
                "</when>",
                "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                    "AND t.teacher_id = ${teacherId}",
                "</when>",
                "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                    "AND t.school_id IN (${schoolId}) ",
                "</when>",
                "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                    "AND t.subjects_id in (${subjectsId}) ",
                "</when>",
                ") OR (",
                "t.teacher_id = ${leadDataRs.teacherId} AND t.school_id IN ( ${leadDataRs.schoolIds} ) AND t.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
            // ---权限数据结束---
            "ORDER BY t.residue_course_count DESC ",
            "</script>"})
    public abstract IPage<ContinueInfo> getRenewRecordDetailV2(IPage<?> iPage, @Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("teacherId") String teacherId, @Param("gradeId") String gradeId, @Param("yearClassId") String yearClassId, @Param("classTypeId") String classTypeId, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs, @Param("paymentStaff") Integer paymentStaff, @Param("paymentStaffType") Integer paymentStaffType, @Param("departmentId") String departmentId, @Param("dutyType") Integer dutyType, @Param("paymentStaffId") String paymentStaffId, @Param("isHistory") Integer isHistory, @Param("detailType") Integer detailType);


    /**
     * 获取缴费率里的人数
     * @param wrapper
     * @return
     */
    @Select("select IFNULL(count(countNum),0) as all_count from (select count(id) as countNum from teacher_continue_info as t ${ew.customSqlSegment}) as t2")
    public abstract Integer getContinueInfoCount(@Param(Constants.WRAPPER) Wrapper wrapper);

    @Select({"<script>",
            "SELECT",
            "*,",
            "count(id) as student_all_count,",
            "team_id AS marketTeacherId,",
            "getStaffNameForId(teacher_id) as teacher_name,",
            "getSchoolName(school_id) as school_name,",
            "SUM( CASE WHEN is_presort in(1,2,3) THEN 1 ELSE 0 END ) AS scheduling_count,",
            "SUM( CASE WHEN is_presort in(1,2,3) and presort_date BETWEEN #{startDate} AND #{endDate}  THEN 1 ELSE 0 END ) AS date_scheduling_count",
            "FROM",
            "(",
            "SELECT",
            "t01.id,",
            "t01.school_id,",
            "t01.year_class_id,",
            "t01.course_type_id,",
            "t01.student_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.grade_name,",
            "t01.subjects_id,",
            "t01.lesson_type,",
            "t02.is_presort,",
            "DATE_FORMAT( t02.created_at, '%Y-%m-%d' ) AS presort_date,",
            "t04.team_id,",
            "t04.team_pid,",
            "t04.NAME AS team_name ",
            "FROM",
            "(",
            "SELECT",
            "t1.id,",
            "( CASE WHEN t8.in_school_id IS NOT NULL THEN t8.in_school_id ELSE t1.school_id END ) AS school_id,",
            "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t1.teacher_id END ) AS teacher_id,",
            "t1.year_class_id,",
            "t1.course_type_id,",
            "t1.student_id,",
            "t1.grade_id,",
            "t1.grade_name,",
            "t1.subjects_id,",
            "t1.lesson_type ",
            "FROM",
            "student_grade_view AS t1 ",
            "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
            "AND t7.deleted = 0 ",
            "AND t7.type = 1 ",
            "AND t1.student_id = t7.student_id ",
            "AND t1.year_part = t7.year_part ",
            "AND t1.quarter_num = t7.quarter_num ",
            "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
            "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
            "AND t1.quarter_num = t8.quarter_num ",
            "AND t1.subjects_id = t8.subjects_id ",
            "AND t1.student_id = t8.student_id ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = ${lessonType} ",
            "AND t7.id IS NULL ",
            "AND t1.deleted = 0 ",
            "AND t1.`status` = 1 ",
            "AND t1.is_last = 1 ",
            "AND t1.is_makeup = 0",
            "AND (t1.reading_status IN ( 1, 4, 5, 6 ) OR ( t1.reading_status = 3 AND t1.use_course_count &gt; 0 )) ",
            "AND t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                "<when test='quarterNum==2'>",
                "and t1.year_class_id &lt; 10",
                "</when>",
                "<when test='quarterNum!=2'>",
                "and t1.year_class_id &lt; 10",
                "</when>",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
                "and t1.year_class_id IN (${yearClassId}) ",
            "</when>",
            "GROUP BY",
            "t1.school_id,",
            "t1.student_id,",
            "t1.teacher_id,",
            "t1.subjects_id ",
            ") AS t01",
            "LEFT JOIN (",
            "SELECT",
            " * ",
            "FROM",
            "student_grade ",
            "WHERE",
            "year_part = ${nextYearPart} ",
            "AND quarter_num = ${nextQuarterNum} ",
            "AND lesson_type = ${lessonType} ",
            "AND deleted = 0 ",
            "AND is_presort in(1,2,3) ",
            "GROUP BY",
            "student_id,",
            "subjects_id ",
            ") AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id ",
            "INNER JOIN (",
            "SELECT ",
            "td.*,",
            "tm.teacher_id,",
            "tm.`name`,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM ",
            "track_detail AS td ",
            "INNER JOIN track_market AS tm ON tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum }",
            "AND tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.STATUS = 1 ",
            "AND tm.deleted = 0 ",
            "<when test='trackId!=null and trackId!=&apos;&apos;'>",
            "  and tm.teacher_id in(select sourse_id from track_detail where deleted = 0 and track_id =#{trackId})",
            "</when>",
            "GROUP BY td.track_id,td.sourse_id ",
            ") AS t04 ON t01.teacher_id = t04.sourse_id ",
            "AND ( find_in_set( t01.year_class_id, t04.year_class_id_str ) OR t04.year_class_id_str = '' ) ",
            "AND ( find_in_set( t01.school_id, t04.school_id_str ) OR t04.school_id_str = '' ) ",
            "AND ( find_in_set( t01.course_type_id, t04.class_type_id_str ) OR t04.class_type_id_str = '' ) ",
            ") AS t",
            "where 1=1",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "and school_id in(${schoolId})",
            "</when>",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                "<when test='quarterNum==2'>",
                "and year_class_id &lt; 13",
                "</when>",
                "<when test='quarterNum!=2'>",
                "and year_class_id &lt; 13",
                "</when>",
            "</when>",
                "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
            "and year_class_id IN (${yearClassId}) ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
            "and course_type_id IN (${classTypeId})",
            "</when>",
            "GROUP BY",
            "team_id",
            "</script>"})
    public abstract List<ContinueInfo> getRenewRecordMarket(@Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum,@Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType,@Param("yearClassId") String yearClassId,@Param("classTypeId") String classTypeId, @Param("classify") Integer classify, @Param("trackType") Integer trackType,@Param("trackId") String trackId);

    @Select({"<script>",
            "SELECT",
            "*,",
            "count(id) as student_all_count,",
            "team_id AS marketTeacherId,",
            "getStaffNameForId(teacher_id) as teacher_name,",
            "getSchoolName(school_id) as school_name,",
            "SUM( CASE WHEN is_presort in(1,2,3) THEN 1 ELSE 0 END ) AS scheduling_count,",
            "SUM( CASE WHEN is_presort in(1,2,3) and presort_date BETWEEN #{startDate} AND #{endDate}  THEN 1 ELSE 0 END ) AS date_scheduling_count",
            "FROM",
            "(",
            "SELECT",
            "t01.id,",
            "t01.school_id,",
            "t01.year_class_id,",
            "t01.course_type_id,",
            "t01.student_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.grade_name,",
            "t01.subjects_id,",
            "t01.lesson_type,",
            "t02.is_presort,",
            "DATE_FORMAT( t02.created_at, '%Y-%m-%d' ) AS presort_date,",
            "t04.team_id,",
            "t04.team_pid,",
            "t04.sourse_id,",
            "t04.NAME AS team_name, ",
            "getStaffNameForId(t04.sourse_id) AS teacherName ",
            "FROM",
            "(",
            "SELECT",
            "t1.id,",
            "( CASE WHEN t8.in_school_id IS NOT NULL THEN t8.in_school_id ELSE t1.school_id END ) AS school_id,",
            "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t1.teacher_id END ) AS teacher_id,",
            "t1.year_class_id,",
            "t1.course_type_id,",
            "t1.student_id,",
            "t1.grade_id,",
            "t1.grade_name,",
            "t1.subjects_id,",
            "t1.lesson_type ",
            "FROM",
            "student_grade_view AS t1 ",
            "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
            "AND t7.deleted = 0 ",
            "AND t7.type = 1 ",
            "AND t1.student_id = t7.student_id ",
            "AND t1.year_part = t7.year_part ",
            "AND t1.quarter_num = t7.quarter_num ",
            "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
            "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
            "AND t1.quarter_num = t8.quarter_num ",
            "AND t1.subjects_id = t8.subjects_id ",
            "AND t1.student_id = t8.student_id ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = ${lessonType} ",
            "AND t7.id IS NULL ",
            "AND t1.deleted = 0 ",
            "AND t1.`status` = 1 ",
            "AND t1.is_last = 1 ",
            "AND t1.is_makeup = 0",
            "AND (t1.reading_status IN ( 1, 4, 5, 6 ) OR ( t1.reading_status = 3 AND t1.use_course_count &gt; 0 )) ",
            "AND t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
            "<when test='quarterNum==2'>",
            "and t1.year_class_id &lt; 10",
            "</when>",
            "<when test='quarterNum!=2'>",
            "and t1.year_class_id &lt; 10",
            "</when>",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
            "and t1.year_class_id IN (${yearClassId}) ",
            "</when>",
            "GROUP BY",
            "t1.school_id,",
            "t1.student_id,",
            "t1.teacher_id,",
            "t1.subjects_id ",
            ") AS t01",
            "LEFT JOIN (",
            "SELECT",
            " * ",
            "FROM",
            "student_grade ",
            "WHERE",
            "year_part = ${nextYearPart} ",
            "AND quarter_num = ${nextQuarterNum} ",
            "AND lesson_type = ${lessonType} ",
            "AND deleted = 0 ",
            "AND is_presort in(1,2,3) ",
            "GROUP BY",
            "student_id,",
            "subjects_id ",
            ") AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id ",
            "INNER JOIN (",
            "SELECT ",
            "td.*,",
            "tm.teacher_id,",
            "tm.`name`,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM ",
            "track_detail AS td ",
            "INNER JOIN track_market AS tm ON tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum }",
            "AND tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.STATUS = 1 ",
            "AND tm.deleted = 0 ",
            "<when test='trackId!=null and trackId!=&apos;&apos;'>",
            "  and tm.teacher_id in(select sourse_id from track_detail where deleted = 0 and track_id =#{trackId})",
            "</when>",
            "GROUP BY td.track_id,td.sourse_id ",
            ") AS t04 ON t01.teacher_id = t04.sourse_id ",
            "AND ( find_in_set( t01.year_class_id, t04.year_class_id_str ) OR t04.year_class_id_str = '' ) ",
            "AND ( find_in_set( t01.school_id, t04.school_id_str ) OR t04.school_id_str = '' ) ",
            "AND ( find_in_set( t01.course_type_id, t04.class_type_id_str ) OR t04.class_type_id_str = '' ) ",
            ") AS t",
            "where team_id = ${teamId} ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "and school_id in(${schoolId})",
            "</when>",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
            "<when test='quarterNum==2'>",
            "and year_class_id &lt; 10",
            "</when>",
            "<when test='quarterNum!=2'>",
            "and year_class_id &lt; 10",
            "</when>",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
            "and year_class_id IN (${yearClassId}) ",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
            "and course_type_id IN (${classTypeId})",
            "</when>",
            "GROUP BY",
            "team_id,sourse_id",
            "</script>"})
    public abstract IPage<ContinueInfo> getRenewRecordDetailMarket(IPage<?> iPage, @Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("teamId") String teamId, @Param("gradeId") String gradeId,@Param("yearClassId") String yearClassId,@Param("classTypeId") String classTypeId, @Param("classify") Integer classify, @Param("trackType") Integer trackType,@Param("trackId") String trackId);

    @Select({"<script>",
            "SELECT",
            "t01.id,",
            "t01.school_id,",
            "t01.year_class_id,",
            "t01.course_type_id,",
            "t01.student_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t01.grade_name,",
            "t01.student_name,",
            "t01.subjects_id,",
            "t01.lesson_type,",
            "t02.is_presort,",
            "DATE_FORMAT( t02.created_at, '%Y-%m-%d' ) AS presort_date,",
            "t04.team_id,",
            "t04.team_pid,",
            "t01.teacher_id AS sourse_id,",
            "t04.NAME AS team_name, ",
            "getStaffNameForId(t01.tack_teacher_id) AS teacherName, ",
            "sum( residue_course_count_all ) AS residue_course_count ",
            "FROM",
            "(",
            "SELECT",
            "t1.id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.student_name,",
            "t1.grade_id,",
            "t1.grade_name,",
            "t1.year_class_id,",
            "t1.course_type_id,",
            "t1.lesson_type,",
            "t1.teacher_id AS tack_teacher_id,",
            "( CASE WHEN t8.in_school_id IS NOT NULL THEN t8.in_school_id ELSE t1.school_id END ) AS school_id,",
            "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t1.teacher_id END ) AS teacher_id, ",
            "sum(IFNULL( t9.residue_course_count, 0 )) AS residue_course_count_all ",
            "FROM",
            "student_grade_view AS t1",
            "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
            "AND t7.deleted = 0 ",
            "AND t7.type = 1 ",
            "AND t1.student_id = t7.student_id ",
            "AND t1.year_part = t7.year_part ",
            "AND t1.quarter_num = t7.quarter_num ",
            "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
            "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
            "AND t1.quarter_num = t8.quarter_num ",
            "AND t1.subjects_id = t8.subjects_id ",
            "AND t1.student_id = t8.student_id ",
            "LEFT JOIN order_detail AS t9 ON t9.student_id = t1.student_id ",
            "AND t9.school_id = t1.school_id",
            "AND t9.subjects_id = t1.subjects_id",
            "AND t9.year_part = t1.year_part",
            "AND t9.lesson_type = t1.lesson_type",
            "AND t9.quarter_num = t1.quarter_num",
            "AND t9.STATUS &lt;&gt; 2",
            "AND t9.deleted = 0",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = ${lessonType} ",
            "AND t7.id IS NULL ",
            "AND t1.deleted = 0 ",
            "AND t1.`status` = 1 ",
            "AND t7.id IS NULL ",
            "AND t1.is_last = 1 ",
            "AND t1.is_makeup = 0",
            "AND (t1.reading_status IN ( 1, 4, 5, 6 ) OR ( t1.reading_status = 3 AND t1.use_course_count &gt; 0 )) ",
            "AND t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                "<when test='quarterNum==2'>",
                    "and t1.year_class_id &lt; 10",
                "</when>",
                "<when test='quarterNum!=2'>",
                    "and t1.year_class_id &lt; 10",
                "</when>",
            "</when>",

            "GROUP BY",
            "t1.school_id,",
            "t1.student_id,",
            "t1.teacher_id,",
            "t1.subjects_id ",
            ") AS t01",
            "LEFT JOIN (",
            "SELECT",
            " * ",
            "FROM",
            "student_grade ",
            "WHERE",
            "year_part = ${nextYearPart} ",
            "AND quarter_num = ${nextQuarterNum} ",
            "AND lesson_type = ${lessonType} ",
            "AND deleted = 0 ",
            "AND is_presort in(1,2,3) ",
            "GROUP BY",
            "student_id,",
            "subjects_id ",
            ") AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id ",
            "INNER JOIN (",
            "SELECT ",
            "td.*,",
            "tm.teacher_id,",
            "tm.`name`,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM ",
            "track_detail AS td ",
            "INNER JOIN track_market AS tm ON tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum}",
            "AND tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.STATUS = 1 ",
            "AND tm.deleted = 0 ",
            "<when test='trackId!=null and trackId!=&apos;&apos;'>",
            "  and tm.teacher_id in(select sourse_id from track_detail where deleted = 0 and track_id =#{trackId})",
            "</when>",
            "GROUP BY td.track_id,td.sourse_id ",
            ") AS t04 ON t01.teacher_id = t04.sourse_id ",
            "AND ( find_in_set( t01.year_class_id, t04.year_class_id_str ) OR t04.year_class_id_str = '' ) ",
            "AND ( find_in_set( t01.school_id, t04.school_id_str ) OR t04.school_id_str = '' ) ",
            "AND ( find_in_set( t01.course_type_id, t04.class_type_id_str ) OR t04.class_type_id_str = '' ) ",
            "where team_id = ${teamId} ",
            "AND sourse_id = ${sourseId} ",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                "<when test='quarterNum==2'>",
                    "and t01.year_class_id &lt; 10",
                "</when>",
                "<when test='quarterNum!=2'>",
                    "and t01.year_class_id &lt; 10",
                "</when>",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
                "and t01.course_type_id IN (${classTypeId})",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
                "and t01.grade_id = ${gradeId}",
            "</when>",
            "<when test='detailType!=null and detailType!=&apos;&apos;'>",
                "<when test='detailType == 1'>",
                "and t02.is_presort IN ( 1, 2, 3 )",
                "</when>",
                "<when test='detailType == 3'>",
                "and t02.is_presort IN ( 1, 2, 3 ) AND DATE_FORMAT( t02.created_at, '%Y-%m-%d' ) BETWEEN #{startDate} AND #{endDate} ",
                "</when>",
            "</when>",

            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "t01.year_class_id in(${authAdminContent.yearClassIds})",
            "and t01.subjects_id in(${authAdminContent.subjectsIds})",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
            "and t01.year_class_id IN (${yearClassId}) ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id = ${subjectsId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "and t01.school_id in(${schoolId})",
            "</when>",
            ") OR (",
            "t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t01.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
            // ---权限数据结束---

            "GROUP BY",
            "school_id,",
            "student_id,",
            "subjects_id, ",
            "teacher_id ",
            "ORDER BY residue_course_count DESC ",
            "</script>"})
    public abstract IPage<ContinueInfo> getRenewRecordDetailMarketBySourseId(IPage<?> iPage, @Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("teamId") String teamId, @Param("gradeId") String gradeId, @Param("yearClassId") String yearClassId, @Param("classTypeId") String classTypeId, @Param("sourseId") String sourseId, @Param("detailType") String detailType, @Param("classify") Integer classify, @Param("trackType") Integer trackType, @Param("trackId") String trackId, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);


    @Select({"<script>",
            "SELECT",
            "*,",
            "count(id) as student_all_count,",
            "getStaffNameForId(teacher_id) as teacher_name,",
            "getSchoolName(school_id) as school_name,",
            "SUM( CASE WHEN is_presort in(1,2,3) THEN 1 ELSE 0 END ) AS scheduling_count,",
            "SUM( CASE WHEN is_presort in(1,2,3) and presort_date BETWEEN #{startDate} AND #{endDate}  THEN 1 ELSE 0 END ) AS date_scheduling_count",
            "FROM",
            "(",
                "SELECT",
                "t01.id,",
                "t01.school_id,",
                "t01.year_class_id,",
                "t01.course_type_id,",
                "t01.student_id,",
                "t01.grade_id,",
                "t01.teacher_id,",
                "t01.grade_name,",
                "t01.subjects_id,",
                "t01.lesson_type,",
                "t02.is_presort,",
                "DATE_FORMAT(t02.created_at, '%Y-%m-%d') as presort_date,",
                "t04.teacher_id AS market_teacher_id,",
                "t04.team_name,",
                "t04.team_id,",
                "t04.team_pid",
                "FROM",
                "(",
                    "SELECT",
                    "t1.id,",
                    "t1.subjects_id, ",
                    "t1.student_id,",
                    "t1.grade_id,",
                    "t1.grade_name,",
                    "t1.year_class_id,",
                    "t1.course_type_id,",
                    "t1.lesson_type,",
                    "t1.teacher_id AS tack_teacher_id,",
                    "( CASE WHEN t8.in_school_id IS NOT NULL THEN t8.in_school_id ELSE t1.school_id END ) AS school_id,",
                    "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t1.teacher_id END ) AS teacher_id ",
                    "FROM",
                    "student_grade_view AS t1 ",
                    "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
                    "AND t7.deleted = 0 ",
                    "AND t7.type = 1 ",
                    "AND t1.student_id = t7.student_id ",
                    "AND t1.year_part = t7.year_part ",
                    "AND t1.quarter_num = t7.quarter_num ",
                    "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
                    "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
                    "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
                    "AND t1.quarter_num = t8.quarter_num ",
                    "AND t1.subjects_id = t8.subjects_id ",
                    "AND t1.student_id = t8.student_id ",
                    "WHERE",
                    "t1.year_part = ${yearPart} ",
                    "AND t1.quarter_num = ${quarterNum} ",
                    "AND t1.lesson_type = ${lessonType} ",
                    "AND t1.deleted = 0 ",
                    "AND t1.STATUS = 1 ",
                    "AND t7.id IS NULL ",
                    "AND t1.is_last = 1 ",
                    "and t1.is_makeup = 0",
                    "and (t1.reading_status in(1,4,5,6) or (t1.reading_status = 3 and t1.use_course_count &gt; 0))",
                    "and t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
                    "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                        "<when test='quarterNum==2'>",
                            "and t1.year_class_id&lt;9",
                        "</when>",
                        "<when test='quarterNum!=2'>",
                            "and t1.year_class_id&lt;10",
                        "</when>",
                    "</when>",
                    "GROUP BY",
                    "t1.school_id,",
                    "t1.student_id,",
                    "t1.teacher_id,",
                    "t1.subjects_id ",
                ") AS t01",

                "LEFT JOIN (",
                    "SELECT",
                    "* ",
                    "FROM",
                    "student_grade ",
                    "WHERE",
                    "year_part = ${nextYearPart} ",
                    "AND quarter_num = ${nextQuarterNum} ",
                    "AND lesson_type = ${lessonType} ",
                    "AND deleted = 0 ",
                    "AND is_presort in(1,2,3) ",
                    "GROUP BY",
                    "student_id,",
                    "subjects_id ",
                ") AS t02 ON t01.student_id = t02.student_id ",
                "AND t01.subjects_id = t02.subjects_id",

                "INNER JOIN ( ",
                    "SELECT ",
                    "td.*, ",
                    "tm.teacher_id,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
                    "FROM ",
                    "track_detail AS td ",
                    "INNER JOIN track_market AS tm ON tm.year_part = ${yearPart} ",
                    "AND tm.quarter_num = ${quarterNum} ",
                    "AND tm.id = td.track_id ",
                    "AND tm.deleted = td.deleted ",
                    "WHERE ",
                    "tm.classify = ${classify} ",
                    "AND tm.track_type = ${trackType} ",
                    "AND tm.`status` = 1 ",
                    "AND tm.deleted = 0 ",
                    "<when test='teamId!=null and teamId!=&apos;&apos; '>",
                    "AND tm.id in (${teamId}) ",
                    "</when>",
                    "GROUP BY ",
                    "td.track_id,td.sourse_id ",
                ") AS t04 ON t01.teacher_id = t04.sourse_id ",
                "AND ( find_in_set( t01.year_class_id, t04.year_class_id_str ) OR t04.year_class_id_str = '' ) ",
                "AND ( find_in_set( t01.school_id, t04.school_id_str ) OR t04.school_id_str = '' ) ",
                "AND ( find_in_set( t01.course_type_id, t04.class_type_id_str ) OR t04.class_type_id_str = '' ) ",

            ") AS t",
            "where 1=1",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type != 4'>",
                "and teacher_id in(select sourse_id from track_detail where deleted = 0 and track_id = ${trackId})",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type == 4'>",
                "and school_id in(select sourse_id from track_detail where deleted = 0 and track_id = ${trackId})",
            "</when>",
            "<if test= 'type == 3'>",
                "and teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
            "</if>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
            "and course_type_id IN (${classTypeId})",
            "</when>",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "year_class_id in(${authAdminContent.yearClassIds})",
            "and subjects_id in(${authAdminContent.subjectsIds})",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
                "and year_class_id IN (${yearClassId})",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "and subjects_id IN (${subjectsId}) ",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                "and school_id IN (${schoolId})",
            "</when>",
            ") OR (",
            "teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
            // ---权限数据结束---
            "GROUP BY",
            "team_id",
            "</script>"})
    public abstract List<ContinueInfo> getRenewRecordTeam(@Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("trackId") String trackId, @Param("yearClassId") String yearClassId, @Param("classTypeId") String classTypeId, @Param("teamId") String teamId, @Param("trackType") Integer trackType, @Param("classify") Integer classify, @Param("isHistorry") Integer isHistorry, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    @Select({"<script>",
            "SELECT",
            "*,",
            "getStaffNameForId ( teacher_id ) AS teacher_name,",
            "getSchoolName ( school_id ) AS school_name",
            "FROM",
            "(",
            "SELECT",
            "t01.id,",
            "t01.school_id,",
            "t03.year_class_id,",
            "t03.course_type_id,",
            "t01.student_id,",
            "t01.grade_id,",
            "t03.teacher_id,",
            "t03.`name` AS grade_name,",
            "t01.subjects_id,",
            "t01.lesson_type,",
            "t02.is_presort,",
            "t04.`name` as student_name,",
            "DATE_FORMAT( t02.created_at, '%Y-%m-%d' ) AS presort_date ",
            "FROM",
            "(",
            "SELECT",
            "* ",
            "FROM",
            "student_grade ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND lesson_type = 1 ",
            "AND deleted = 0 ",
            "AND STATUS = 1 ",
            "AND is_last = 1 ",
            "and is_makeup = 0",
            "and (reading_status in(1,4,5,6) or (reading_status=3 and use_course_count&gt;0))",
            "and student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",

            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                "<when test='quarterNum==2'>",
                    "and year_class_id&lt;9",
                "</when>",
                "<when test='quarterNum!=2'>",
                    "and year_class_id&lt;10",
                "</when>",
            "</when>",
            "GROUP BY",
            "school_id,",
            "student_id,",
            "subjects_id ",
            ") AS t01",
            "LEFT JOIN (",
            "SELECT",
            "* ",
            "FROM",
            "student_grade ",
            "WHERE",
            "year_part = ${nextYearPart} ",
            "AND quarter_num = ${nextQuarterNum}",
            "AND lesson_type = 1 ",
            "AND deleted = 0 ",
            "AND is_presort in(1,2,3) ",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
                "<when test='quarterNum==2'>",
                    "and year_class_id&lt;9",
                "</when>",
                "<when test='quarterNum!=2'>",
                    "and year_class_id&lt;10",
                "</when>",
            "</when>",
            "GROUP BY",
            "student_id,",
            "subjects_id ",
            ") AS t02 ON t01.student_id = t02.student_id",
            "AND t01.subjects_id = t02.subjects_id",
            "LEFT JOIN grade AS t03 ON t01.grade_id = t03.id",
            "LEFT JOIN student AS t04 ON t01.student_id = t04.id",

            "INNER JOIN ( ",
            "SELECT ",
            "td.*, ",
            "tm.teacher_id,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
            "FROM ",
            "track_detail AS td ",
            "INNER JOIN track_market AS tm ON tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "AND tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            "AND tm.id in (${teamId}) ",
            "</when>",
            "GROUP BY ",
            "td.track_id,td.sourse_id ",
            ") AS t05 ON t03.teacher_id = t05.sourse_id ",
            "AND ( find_in_set( t03.year_class_id, t05.year_class_id_str ) OR t05.year_class_id_str = '' ) ",
            "AND ( find_in_set( t03.school_id, t05.school_id_str ) OR t05.school_id_str = '' ) ",
            "AND ( find_in_set( t03.course_type_id, t05.class_type_id_str ) OR t05.class_type_id_str = '' ) ",

            ") AS t ",
            "WHERE",
            "1 = 1 ",
            "and is_presort in(1,2,3)",
            "<if test= 'type == 1 or type == 2 or type == 3'>",
                "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
                    "and teacher_id = ${teacherId}",
                "</when>",
            "</if>",
            "<if test= 'type == 2 or type == 4'>",
                "<when test='schoolId!=null and schoolId!=&apos;&apos;'>",
                    "and school_id = ${schoolId}",
                "</when>",
            "</if>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and grade_id=${gradeId}",
            "</when>",
            "<when test='startDate!=&apos;&apos; and endDate!=&apos;&apos;'>",
            "and presort_date BETWEEN #{startDate} AND #{endDate}",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
            "and year_class_id IN (${yearClassId})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
            "and course_type_id IN (${classTypeId})",
            "</when>",
            "</script>"})
    public abstract IPage<ContinueInfo> getRenewRecordDetailTeam(IPage<?> iPage, @Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("teacherId") String teacherId, @Param("gradeId") String gradeId,@Param("yearClassId") String yearClassId,@Param("classTypeId") String classTypeId,@Param("teamId") String teamId,@Param("trackType") Integer trackType,@Param("classify") Integer classify,@Param("isHistorry") Integer isHistorry);

@Select({"<script>",
        "SELECT",
        "*,",
        "count(id) as student_all_count,",
        "getStaffNameForId(teacher_id) as teacher_name,",
        "getSchoolName(school_id) as school_name,",
        "SUM( CASE WHEN is_presort in(1,2,3) THEN 1 ELSE 0 END ) AS scheduling_count,",
        "SUM( CASE WHEN is_presort in(1,2,3) and presort_date BETWEEN #{startDate} AND #{endDate}  THEN 1 ELSE 0 END ) AS date_scheduling_count",
        "FROM",
        "(",
        "SELECT",
        "t01.id,",
        "t01.school_id,",
        "t01.year_class_id,",
        "t01.course_type_id,",
        "t01.student_id,",
        "t01.grade_id,",
        "t01.teacher_id,",
        "t01.grade_name ,",
        "t01.subjects_id,",
        "t01.lesson_type,",
        "t02.is_presort,",
        "DATE_FORMAT(t02.created_at, '%Y-%m-%d') as presort_date,",
        "t04.teacher_id AS market_teacher_id,",
        "t04.team_name,",
        "t04.team_id,",
        "t04.team_pid",
        "FROM",
        "(",
        "SELECT",
        "t1.id,",
        "t1.subjects_id,",
        "t1.student_id,",
        "t1.grade_id,",
        "t1.grade_name,",
        "t1.year_class_id,",
        "t1.course_type_id,",
        "t1.lesson_type,",
        "t1.teacher_id AS tack_teacher_id,",
        "( CASE WHEN t8.in_school_id IS NOT NULL THEN t8.in_school_id ELSE t1.school_id END ) AS school_id,",
        "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t1.teacher_id END ) AS teacher_id ",
        "FROM",
        "student_grade_view AS t1",
        "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
        "AND t7.deleted = 0 ",
        "AND t7.type = 1 ",
        "AND t1.student_id = t7.student_id ",
        "AND t1.year_part = t7.year_part ",
        "AND t1.quarter_num = t7.quarter_num ",
        "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
        "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
        "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
        "AND t1.quarter_num = t8.quarter_num ",
        "AND t1.subjects_id = t8.subjects_id ",
        "AND t1.student_id = t8.student_id ",
        "WHERE",
        "t1.year_part = ${yearPart} ",
        "AND t1.quarter_num = ${quarterNum} ",
        "AND t1.lesson_type = ${lessonType} ",
        "AND t1.deleted = 0 ",
        "AND t1.STATUS = 1 ",
        "AND t1.is_last = 1 ",
        "AND t7.id IS NULL ",
        "and t1.is_makeup = 0",
        "and (t1.reading_status in(1,4,5,6) or (t1.reading_status=3 and t1.use_course_count&gt;0))",
        "and t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
        "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
            "<when test='quarterNum==2'>",
                "and t1.year_class_id&lt;9",
            "</when>",
            "<when test='quarterNum!=2'>",
                "and t1.year_class_id&lt;10",
            "</when>",
        "</when>",
        "GROUP BY",
        "t1.school_id,",
        "t1.student_id,",
        "t1.teacher_id,",
        "t1.subjects_id ",
        ") AS t01",

        "LEFT JOIN (",
        "SELECT",
        "* ",
        "FROM",
        "student_grade ",
        "WHERE",
        "year_part = ${nextYearPart} ",
        "AND quarter_num = ${nextQuarterNum} ",
        "AND lesson_type = ${lessonType} ",
        "AND deleted = 0 ",
        "AND is_presort in(1,2,3) ",
        "GROUP BY",
        "student_id,",
        "subjects_id ",
        ") AS t02 ON t01.student_id = t02.student_id ",
        "AND t01.subjects_id = t02.subjects_id",

        "INNER JOIN ( ",
        "SELECT ",
        "td.*, ",
        "tm.teacher_id,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
        "FROM ",
        "track_detail AS td ",
        "INNER JOIN track_market AS tm ON tm.year_part = ${yearPart} ",
        "AND tm.quarter_num = ${quarterNum} ",
        "AND tm.id = td.track_id ",
        "AND tm.deleted = td.deleted ",
        "WHERE ",
        "tm.classify = ${classify} ",
        "AND tm.track_type = ${trackType} ",
        "AND tm.`status` = 1 ",
        "AND tm.deleted = 0 ",
        "<when test='teamId!=null and teamId!=&apos;&apos; '>",
        "AND tm.id in (${teamId}) ",
        "</when>",
        "GROUP BY ",
        "td.track_id,td.sourse_id ",
        ") AS t04 ON t01.teacher_id = t04.sourse_id ",
        "AND ( find_in_set( t01.year_class_id, t04.year_class_id_str ) OR t04.year_class_id_str = '' ) ",
        "AND ( find_in_set( t01.school_id, t04.school_id_str ) OR t04.school_id_str = '' ) ",
        "AND ( find_in_set( t01.course_type_id, t04.class_type_id_str ) OR t04.class_type_id_str = '' ) ",

        ") AS t",
        "where 1=1",
        "<when test='trackId!=null and trackId!=&apos;&apos; and type != 4'>",
        "and teacher_id in(select sourse_id from track_detail where deleted = 0 and track_id = ${trackId})",
        "</when>",
        "<when test='trackId!=null and trackId!=&apos;&apos; and type == 4'>",
        "and school_id in(select sourse_id from track_detail where deleted = 0 and track_id = ${trackId})",
        "</when>",
        "<if test= 'type == 3'>",
        "and teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
        "</if>",
        "<when test='classTypeId!=null and classTypeId!=&apos;&apos; '>",
        "and course_type_id IN (${classTypeId})",
        "</when>",

        // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
        "and ((",
        "year_class_id in (${yearClassId}) ",
        "and subjects_id IN (${subjectsId})  ",
        "and school_id in(${schoolId}) ",
        "<when test='authAdminContent.isPerson==1'>",
        "and teacher_id = ${authAdminContent.teacherId} ",
        "</when>",
        ") or (teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
        // ---权限数据结束---

        "GROUP BY",
        "teacher_id,team_id ",
        "</script>"})
public abstract List<ContinueInfo> getRenewRecordDetailTeamTeacher(@Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("trackId") String trackId, @Param("yearClassId") String yearClassId, @Param("classTypeId") String classTypeId, @Param("teamId") String teamId, @Param("trackType") Integer trackType, @Param("classify") Integer classify, @Param("isHistorry") Integer isHistorry, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    /**
     * 带班人数 续报率
     */
    @Select({"<script>",
            "SELECT",
            "student_all_count AS gradeStudentCount,",
            "SUM( student_all_count ) AS student_all_count,",
            "SUM( scheduling_count ) AS scheduling_count,",
            "teacher_id,",
            "teacher_name,",
            "school_id,",
            "school_name,",
            "subjects_id,",
            "year_class_id ",
            "FROM ",
            "(",

            "SELECT",
            "t.*,",
            "count(t.id) as student_all_count,",
            "getSchoolName(t.school_id) as school_name,",
            "SUM( CASE WHEN is_presort in(1,2,3) THEN 1 ELSE 0 END ) AS scheduling_count ",
            "<if test= 'type == 6'>",
            ",t01.pid as schoolPid",
            "FROM ",
            "( SELECT * FROM school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t01 ",
            "LEFT JOIN (",
            "</if>",
            "<if test= 'type != 6'>",
            "FROM ( ",
            "</if>",
            "SELECT",
            "t01.id,",
            "t01.school_id,",
            "t03.year_class_id,",
            "t03.course_type_id,",
            "t01.student_id,",
            "t01.grade_id,",
            "t01.teacher_id,",
            "t03.`name` AS grade_name,",
            "t01.subjects_id,",
            "t01.lesson_type,",
            "t02.is_presort,",
            "DATE_FORMAT(t02.created_at, '%Y-%m-%d') as presort_date,",
            "getStaffNameForId(t01.teacher_id) AS teacher_name ",
            "FROM",
            "(",
            "SELECT",
            "t1.id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.grade_id,",
            "t1.lesson_type,",
            "t1.teacher_id AS tack_teacher_id,",
            "( CASE WHEN t8.in_school_id IS NOT NULL THEN t8.in_school_id ELSE t1.school_id END ) AS school_id,",
            "( CASE WHEN t8.schoolmaster_id IS NOT NULL THEN t8.schoolmaster_id ELSE t1.teacher_id END ) AS teacher_id ",
            "FROM",
            "student_grade_view AS t1",
            "LEFT JOIN rade_exclude_student AS t7 ON t7.classify_id = 1 ",
            "AND t7.deleted = 0 ",
            "AND t7.type = 1 ",
            "AND t1.student_id = t7.student_id ",
            "AND t1.year_part = t7.year_part ",
            "AND t1.quarter_num = t7.quarter_num ",
            "AND ( FIND_IN_SET( t1.subjects_id, t7.subjects_ids ) OR t7.subjects_ids IS NULL ) ",
            "AND ( FIND_IN_SET( t1.school_id, t7.school_ids ) OR t7.school_ids IS NULL ) ",
            "LEFT JOIN leave_teacher_student AS t8 ON t1.year_part = t8.year_part ",
            "AND t1.quarter_num = t8.quarter_num ",
            "AND t1.subjects_id = t8.subjects_id ",
            "AND t1.student_id = t8.student_id ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.quarter_num = ${quarterNum} ",
            "AND t1.lesson_type = ${lessonType} ",
            "AND t7.id IS NULL ",
            "AND t1.deleted = 0 ",
            "AND t1.STATUS = 1 ",
            "AND t1.is_last = 1 ",
            "and t1.is_makeup = 0",
            "and (t1.reading_status in(1,4,5,6) or (t1.reading_status=3 and t1.use_course_count&gt;0))",
            "and t1.student_id not in(select student_id from renew_no_student where deleted=0 and year_part =${yearPart} and quarter_num = ${quarterNum})",
            "<if test= 'type != 7'>",
            "<when test='yearClassId==null or yearClassId==&apos;&apos;'>",
            "<when test='quarterNum==2'>",
            "and t1.year_class_id &lt; 10",
            "</when>",
            "<when test='quarterNum!=2'>",
            "and t1.year_class_id &lt; 10",
            "</when>",
            "</when>",
            "</if>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
            "and t1.year_class_id IN (${yearClassId})",
            "</when>",
            "GROUP BY",
            "t1.school_id,",
            "t1.student_id,",
            "t1.teacher_id,",
            "t1.subjects_id ",
            ") AS t01",
            "LEFT JOIN (",
            "SELECT",
            "* ",
            "FROM",
            "student_grade ",
            "WHERE",
            "year_part = ${nextYearPart} ",
            "AND quarter_num = ${nextQuarterNum} ",
            "AND lesson_type = ${lessonType} ",
            "AND deleted = 0 ",
            "AND is_presort in(1,2,3) ",
            "GROUP BY",
            "student_id,",
            "subjects_id ",
            ") AS t02 ON t01.student_id = t02.student_id ",
            "AND t01.subjects_id = t02.subjects_id",
            "LEFT JOIN grade AS t03 ON t01.grade_id = t03.id ",
            ") AS t",
            "<if test= 'type == 6'>",
            "ON t.school_id = t01.school_id ",
            "</if>",
            "where 1=1",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type != 4'>",
            "and t.teacher_id in(select sourse_id from track_detail where deleted = 0 and track_id = ${trackId})",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type == 4'>",
            "and t.school_id in(select sourse_id from track_detail where deleted = 0 and track_id = ${trackId})",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "<if test= 'type == 3'>",
            "and teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
            "</if>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "and t.school_id in(${schoolId})",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos;'>",
            "and year_class_id IN (${yearClassId})",
            "</when>",
            "<when test='classTypeId!=null and classTypeId!=&apos;&apos;'>",
            "and course_type_id IN (${classTypeId})",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and teacher_name LIKE '%${name}%'",
            "</when>",
            "<if test= 'type == 6'>",
            "and t.school_id is not null",
            "</if>",
            "GROUP BY",
            "<if test= 'type == 1 or type == 3'>",
            "t.teacher_id,t.grade_id",
            "</if>",
            "<if test= 'type == 2'>",
            "t.school_id,t.teacher_id",
            "</if>",
            "<if test= 'type == 4 or type == 6'>",
            "t.school_id",
            "</if>",
            "<if test= 'type == 7'>",
            "year_class_id",
            "</if>",
            "<if test= 'type == 7'>",
            "ORDER BY year_class_id DESC",
            "</if>",

            ") AS gt1 ",
            "WHERE ",
            "gt1.student_all_count BETWEEN ${startGradeCount} AND ${endGradeCount} ",
            "GROUP BY teacher_id ",
            "</script>"})
    public abstract List<ContinueInfo> getContinueFeeByTeacherIdList(@Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("nextYearPart") Integer nextYearPart, @Param("nextQuarterNum") Integer nextQuarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type,  @Param("lessonType") Integer lessonType, @Param("trackId") String trackId, @Param("yearClassId") String yearClassId, @Param("classTypeId") String classTypeId, @Param("name") String name, @Param("startGradeCount") String startGradeCount, @Param("endGradeCount") String endGradeCount);

}
